﻿using System.Collections.Generic;
using Monkey.Warrenty.Data;
using Monkey.Warrenty.Data.Interfaces;
using Monkey.Warrenty.EntityModel;
using Monkey.Warrenty.Enum;

namespace Monkey.Warrenty.Biz
{
    public class WarrantyProductBiz
    {
        #region Properties

        private readonly IWarrantyProductDao _warrantyProductDao;
        private readonly IEmployeeDao _employeeDao;
        private readonly ISupplierDao _supplierDao;

        #endregion

        #region Constructors

        public WarrantyProductBiz()
        {
            _warrantyProductDao = new WarrantyProductDao();
            _employeeDao = new EmployeeDao();
            _supplierDao = new SupplierDao();
        }

        #endregion

        #region Medthods

        public List<Supplier> GetSuppliers()
        {
            return _supplierDao.GetAllSuppliers();
        }

        public List<Employee> GetEmployees()
        {
            return _employeeDao.GetAllEmployees();
        }

        public List<WarrantyTicketProductView> GetReceivedWarrantyProductsByFilter(int startIndex, int pageSize, string sorting, string name, string code, string ticketCode)
        {
            return _warrantyProductDao.GetReceivedWarrantyProductsByFilter(startIndex, pageSize, sorting, name, code, ticketCode);
        }

        public int GetReceivedWarrantyProductsCountByFilter(string name, string code, string ticketCode)
        {
            return _warrantyProductDao.GetReceivedWarrantyProductsCountByFilter(name, code, ticketCode);
        }

        public List<WarrantyTicketProductView> GetWaitingWarrantyProducts(int startIndex, int pageSize, string sorting, string name, string code, string ticketCode)
        {
            return _warrantyProductDao.GetWarrantyTicketProductsByFilter(WarrantyProductStatus.WaitingWarranty.GetHashCode(), startIndex, pageSize, sorting, name, code, ticketCode);
        }

        public List<WarrantyTicketLendProductView> GetLendProducts(int startIndex, int pageSize, string sorting)
        {
            return _warrantyProductDao.GetLendProducts(LendProductStatus.Lending.GetHashCode(), startIndex, pageSize, sorting);
        }

        public int GetWaitingWarrantyProductsCount(string name, string code, string ticketCode)
        {
            return _warrantyProductDao.GetWarrantyProductsCountByFilter(WarrantyProductStatus.WaitingWarranty.GetHashCode(), name, code, ticketCode);
        }

        public int GetLendProductsCount()
        {
            return _warrantyProductDao.GetLendProductsCount(LendProductStatus.Lending.GetHashCode());
        }

        public void SendToTechnical(List<long> productIds, int employeeId)
        {
            if (productIds == null || productIds.Count == 0) return;
            _warrantyProductDao.SendToTechnical(productIds, employeeId);
            //_warrantyProductDao.UpdateProductStates(productIds, WarrantyProductStatus.AtTechnical.GetHashCode());
        }

        public void SendToSupplier(List<long> productIds, int supplierId)
        {
            if (productIds == null || productIds.Count == 0) return;
            _warrantyProductDao.SendToSupplier(productIds, supplierId);
        }

        public void ReceivedBack(List<long> productIds)
        {
            if (productIds == null || productIds.Count == 0) return;

            _warrantyProductDao.UpdateLendProductStates(productIds, LendProductStatus.ReceivedBack.GetHashCode());
        }

        public void SendBackCustomer(List<long> productIds)
        {
            if (productIds == null || productIds.Count == 0) return;

            _warrantyProductDao.UpdateProductStates(productIds, WarrantyProductStatus.SentBackCustomer.GetHashCode());
        }

        public void SendToWarrantySupplier(List<long> productIds)
        {
            if (productIds == null || productIds.Count == 0) return;

            _warrantyProductDao.UpdateProductStates(productIds, WarrantyProductStatus.AtSupplier.GetHashCode());
        }

        public List<WarrantyTicketProductView> GetProcessingWarrantyProducts(int startIndex, int pageSize, string sorting)
        {
            return _warrantyProductDao.GetProcessingWarrantyProducts(startIndex, pageSize, sorting);
        }

        public int GetProcessingWarrantyProductsCount()
        {
            return _warrantyProductDao.GetProcessingWarrantyProductsCount();
        }

        public int GetProcessingWarrantyProductsCount(int employeeId)
        {
            return _warrantyProductDao.GetProcessingWarrantyProductsCount(employeeId);
        }

        public int GetWarrantyProductsAtSupplierCount()
        {
            return _warrantyProductDao.GetWarrantyProductsCount(WarrantyProductStatus.AtSupplier.GetHashCode());
        }

        public List<WarrantyTicketProductView> GetWarrantyProductsAtSupplier(int startIndex, int pageSize, string sorting)
        {
            return _warrantyProductDao.GetWarrantyTicketProducts(WarrantyProductStatus.AtSupplier.GetHashCode(), startIndex, pageSize, sorting);
        }

        public int GetWarrantyProductsAtTechnicalCount()
        {
            return _warrantyProductDao.GetWarrantyProductsCount(WarrantyProductStatus.AtTechnical.GetHashCode());
        }

        public List<WarrantyTicketProductView> GetWarrantyProductsAtTechnical(int startIndex, int pageSize, string sorting)
        {
            return _warrantyProductDao.GetWarrantyTicketProducts(WarrantyProductStatus.AtTechnical.GetHashCode(), startIndex, pageSize, sorting);
        }

        public WarrantyTicketProductView GetWarrantyTicketProductView(long id)
        {
            if (id <= 0) return null;
            return _warrantyProductDao.GetWarrantyTicketProductView(id);
        }

        public void UpdateProductStatus(long warrProductId, WarrantyProductStatus status)
        {
            if (warrProductId <= 0) return;

            _warrantyProductDao.UpdateProductStates(new List<long> { warrProductId }, status.GetHashCode());
        }

        public void UpdateProcessProduct(WarrantyTicketProductView productView)
        {
            _warrantyProductDao.UpdateProcessProduct(productView);
        }

        public List<WarrantyTicketProductView> GetProcessingWarrantyProducts(int employeeId, int startIndex, int pageSize, string sorting)
        {
            return _warrantyProductDao.GetProcessingWarrantyProducts(employeeId, startIndex, pageSize, sorting);
        }

        #endregion
    }
}
